package com.study.reactor.rxjava;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
import org.junit.Test;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yuantongqin
 * desc:
 * 2020-11-25
 */
public class Create {

    @Test
    public void create(){

        Single<List<Integer>> collect = Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("1");
                e.onComplete();
            }
        }).subscribeOn(Schedulers.io()).map(Integer::valueOf).collect(Collectors.toList());
        List<Integer> integers = collect.blockingGet();
        System.out.println(integers);
    }


}
